//
//  UserInfoTextField.m
//  itboyeios_gd
//
//  Created by Rajon on 15/11/5.
//  Copyright © 2015年 Boye. All rights reserved.
//

#import "UserTextField.h"

@implementation UserTextField

//自定义初始化方法（图标形式）
- (instancetype)initWithFrame:(CGRect)frame
                     iconName:(NSString *)iconName
                  placeholder:(NSString *)placeholder
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;

        // 创建左端图标
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, self.height-10, self.height-10)];
        icon.image = [UIImage imageNamed:iconName];
        UIView *iconView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.height, self.height)];
        [iconView addSubview:icon];
        self.leftView = iconView;
        self.leftViewMode = UITextFieldViewModeAlways;
        
        // 设置placeholder
        if (![placeholder isStringNull]) {
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.minimumLineHeight = self.height/2;
            NSDictionary *stringAttr = @{
                                         NSFontAttributeName:[UIFont systemFontOfSize:self.height/3],
                                         NSParagraphStyleAttributeName:paragraphStyle
                                         };
            NSAttributedString *palceholderString = [[NSAttributedString alloc] initWithString:placeholder attributes:stringAttr];
            self.attributedPlaceholder = palceholderString;
        }
    }
    return self;
}



@end
